<?php
namespace app\api\model;


use app\model\Base;

class PigBatch extends Base
{
    //购买年猪时 代理处理
    public static function exchangePigBatchMoney($amount)
    {
        $pigBatch = self::column('rate', 'type');

        $provinceRate = $pigBatch['province_money'];
        $provinceAmount = round(($amount * $provinceRate) / 100, 2);

        $cityRate = $pigBatch['city_money'];
        $cityAmount = round(($amount * $cityRate) / 100, 2);

        $areaRate = $pigBatch['area_money'];
        $areaAmount = round(($amount * $areaRate) / 100, 2);

        self::where('type', 'province_money')
            ->inc('amount', $provinceAmount)
            ->update();

        self::where('type', 'city_money')
            ->inc('amount', $cityAmount)
            ->update();

        self::where('type', 'area_money')
            ->inc('amount', $areaAmount)
            ->update();
    }

    //转化时 代理处理
    public static function exchangePigBatchGold($amount)
    {
        $pigBatch = self::column('rate', 'type');

        $provinceRate = $pigBatch['province_gold'];
        $provinceAmount = round(($amount * $provinceRate) / 100, 2);

        $cityRate = $pigBatch['city_gold'];
        $cityAmount = round(($amount * $cityRate) / 100, 2);

        $areaRate = $pigBatch['area_gold'];
        $areaAmount = round(($amount * $areaRate) / 100, 2);

        self::where('type', 'province_gold')
            ->inc('amount', $provinceAmount)
            ->update();

        self::where('type', 'city_gold')
            ->inc('amount', $cityAmount)
            ->update();

        self::where('type', 'area_gold')
            ->inc('amount', $areaAmount)
            ->update();
    }
}